package com.core.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.core.base.dao.BaseHibernateDao;
import com.core.model.RoleCategory;

/**
 * 角色类别DAO
 * 
 * @author pt-chenqw
 *
 */
@Repository("roleCategoryDAO")
public class RoleCategoryDAO extends BaseHibernateDao<RoleCategory> {
	
	/**
	 * 根据ID查询角色类别
	 * @param id
	 * @return
	 */
	public RoleCategory getRoleCategoryByID(Integer id){
		String hql = "from RoleCategory where id = ?";
		return findOne(hql, id);
	}
	
	/**
	 * 保存新增角色类别
	 * @param roleCategory
	 */
	public void addRoleCategory(RoleCategory roleCategory){
		roleCategory.setCreatetime(new Date());
		roleCategory.setUpdatetime(new Date());
		save(roleCategory);
	}
	
	/**
	 * 更新角色类别信息
	 * @param roleCategory
	 */
	public void updateRoleCategory(RoleCategory roleCategory){
		RoleCategory category = getRoleCategoryByID(roleCategory.getId());
		if(category != null){
			category.setCategoryCode(roleCategory.getCategoryCode());
			category.setCategoryName(roleCategory.getCategoryName());
			category.setStatus(roleCategory.getStatus());
			category.setUpdatetime(new Date());
		}
		update(category);
	}
	
	/**
	 * 删除角色类别
	 * @param id
	 */
	public void deleteRoleCategoryByID(Integer id){
		RoleCategory roleCategory = getRoleCategoryByID(id);
		delete(roleCategory);
	}
	
	/**
	 * 根据code查询角色类别
	 * @param code
	 * @return
	 */
	public RoleCategory getRoleCategoryByCode(String code){
		String hql = "from RoleCategory where categoryCode = ?";
		return findOne(hql, code);
	}

}
